<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Resource;

use App\Model\AgentOrder;
use App\Traits\ResourceWith;
use Hyperf\Resource\Json\JsonResource;

class UserResource extends JsonResource
{
    use ResourceWith;

    /**
     * Transform the resource into an array.
     */
    public function toArray(): array
    {
        return [
            'id' => $this->id,
            'nick_name' => $this->nick_name,
            'nick_name' => $this->nick_name,
            'address' => $this->address,
            'invite_code' => $this->invite_code,
            'birthday' => $this->birthday ?? '',
            'avatar' => $this->avatar ?? 'https://gas.msgqu.com/upload/2022-12-05/lriogR8Emp.jpg',
            'sex' => $this->sex,
            'mobile' => $this->mobile,
            'token' => $this->token,
            'is_agent' => AgentOrder::where('uid', $this->id)->exists(),
            'activity_invite_code' => $this->activity_invite_code
            ];
    }
}
